<template>
  <div class="page-container">
    <!--工具栏-->
    <div class="toolbar" style="float:left;padding-top:10px;padding-left:15px;">
      <el-form :inline="true" :model="filters" ref="filters" :size="size">
        <el-row>
          <el-form-item prop="orderno">
            <el-input v-model="filters.orderno" placeholder="订单号"></el-input>
          </el-form-item>
          <el-form-item prop="membername">
            <el-input v-model="filters.username" placeholder="申请人姓名"></el-input>
          </el-form-item>
          <el-form-item prop="productname">
            <el-input v-model="filters.productname" placeholder="商品名称"></el-input>
          </el-form-item>

          <el-form-item prop="startFullMoney">
            <el-input-number size="mini" v-model="filters.startFullMoney" placeholder="金额"></el-input-number>
          </el-form-item>

          <el-form-item prop="endFullMoney">
            <el-input-number size="mini" v-model="filters.endFullMoney" placeholder="金额"></el-input-number>
          </el-form-item>

          <el-form-item prop="paytype">
          <el-select v-model="filters.paytype" style="width: 215px;" placeholder="付款方式">
            <el-option label="微信" value=""></el-option>
            <el-option label="线下" value="0"></el-option>
          </el-select>
        </el-form-item>

          <el-form-item prop="reasontype">
            <el-select v-model="filters.reasontype" style="width: 215px;" placeholder="类型">

                <el-option value="" label="请选择"></el-option>
                <el-option value="0" label="材质问题"></el-option>
                <el-option value="1" label="尺寸问题"></el-option>
                <el-option value="2" label="无法正常使用"></el-option>
                <el-option value="3" label="商品有瑕疵/脏污"></el-option>
                <el-option value="4" label="商品质量问题"></el-option>
                <el-option value="5" label="不好用/穿着不舒服"></el-option>
                <el-option value="6" label="与商品描述不符"></el-option>
                <el-option value="7" label="不喜欢/买错了/买多了"></el-option>
                <el-option value="8" label="商品错发"></el-option>
                <el-option value="9" label="包装破损"></el-option>
                <el-option value="10" label="商品漏发少件"></el-option>
                <el-option value="11" label="其他"></el-option>


            </el-select>
          </el-form-item>

          <el-form-item>
            <kt-button icon="fa fa-search" :label="$t('action.search')" type="primary" @click="findPage(null)"/>
          </el-form-item>

          <el-form-item>
            <kt-button icon="fa fa-refresh" :label="$t('action.reset')" type="primary" @click="resetForm('filters')"/>
          </el-form-item>

          <el-form-item>
            <kt-button label="审核" type="primary" @click="setStaus()" />
          </el-form-item>
        </el-row>

      </el-form>
    </div>
    <div class="toolbar" style="float:right;padding-top:10px;padding-right:15px;">
      <el-form :inline="true" :size="size">
        <el-form-item>
          <el-button-group>
            <el-tooltip content="刷新" placement="top">
              <el-button icon="fa fa-refresh" @click="findPage(null)"></el-button>
            </el-tooltip>
            <el-tooltip content="列显示" placement="top">
              <el-button icon="fa fa-filter" @click="displayFilterColumnsDialog"></el-button>
            </el-tooltip>
     <!--       <el-tooltip content="导出" placement="top">
              <el-button icon="fa fa-file-excel-o" @click="downloadExcel" id="downloadExcel"></el-button>
            </el-tooltip>-->
          </el-button-group>
        </el-form-item>
      </el-form>
      <!--表格显示列界面-->
      <table-column-filter-dialog ref="tableColumnFilterDialog" :columns="columns"
                                  @handleFilterColumns="handleFilterColumns">
      </table-column-filter-dialog>
    </div>
    <!--表格内容栏-->
    <cy-table :height="350"
              :data="pageResult"
              :columns="filterColumns"
              @findPage="findPage"
              @handleDelete="handleDelete"
              :showEditOperation="false"
              @selectionChange="selectionChange"
              ref="CyTable">
    </cy-table>

    <el-dialog
      title="退款处理"
      width="25%"
      :visible.sync="dialogVisibleOpenTime"
      :close-on-click-modal="false"
    >
      <el-form
        :model="dataFormOpenTime"
        label-width="80px"
        :rules="dataFormOpenTimeRules"
        ref="dataFormOpenTime"
        :size="size"
        label-position="right"
      >
        <el-form-item label="ID" prop="id" v-if="false">
          <el-input v-model="dataFormOpenTime.id" :disabled="true" auto-complete="off"></el-input>
        </el-form-item>
        <el-form-item label="申请金额" prop="serveno">
          <el-input v-model="dataFormOpenTime.serveno" :disabled="true" auto-complete="off"></el-input>
        </el-form-item>
        <el-form-item label="状态" prop="status">
          <el-select v-model="dataFormOpenTime.status">
            <el-option
              v-for="item in status"
              :key="item.key"
              :label="item.value"
              :value="item.key"
            ></el-option>
          </el-select>

        </el-form-item>
        <el-form-item label="收货地址" prop="describe">
          <el-input v-model="dataFormOpenTime.describe" auto-complete="off" type="textarea"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer" style="text-align:center">
        <el-button
          :size="size"
          @click.native="dialogVisibleOpenTime = false"
        >{{$t('action.cancel')}}</el-button>
        <el-button
          :size="size"
          type="primary"
          @click="submitFormOpentime"
          :loading="editLoading"
        >{{$t('action.submit')}}</el-button>
      </div>
    </el-dialog>

  </div>
</template>

<script>
  import PopupTreeInput from "@/components/PopupTreeInput"
  import CyTable from "@/views/Core/CyTable"
  import KtButton from "@/views/Core/KtButton"
  import TableColumnFilterDialog from "@/views/Core/TableColumnFilterDialog"
  import {format} from "@/utils/datetime"
  import utils from "@/assets/js/utils.js"

  export default {
    components: {
      PopupTreeInput,
      CyTable,
      KtButton,
      TableColumnFilterDialog
    },
    data() {
      return {
        size: 'small',
        list: [],
        warehouselist: [],
        status: [
          { key: 0, value: "用户申请" },
          { key: 1, value: "客服审核通过" },
          { key: 2, value: "客服审核拒绝" },
          { key: 3, value: "已发货" },
          { key: 4, value: "已收货" },
          { key: 5, value: "店铺审核通过" },
          { key: 6, value: "店铺审核拒绝" },

        ],
        attribute: [{key: 0, value: "自有库"}, {key: 1, value: "委外库"}],
        filters: {
          username: '',
          telephone: '',
          age: '',
          content: ''
        },
        columns: [],
        checked: [],
        filterColumns: [],
        pageRequest: {pageNum: 1, pageSize: 10},
        pageResult: {},
        dialogVisibleOpenTime: false,
        editLoading: false,
        dataFormOpenTimeRules: {
          describe: [
            { required: true, message: "收货地址不能为空", trigger: "blur" }
          ]
        },
        dataFormOpenTime: {
          describe:""
        }

      }
    },

    methods: {

      // 获取分页数据
      findPage: function (data) {
        this.filters.t = 'shopReturn'
        this.$refs.CyTable.findPage(this.filters)
      },

      // 批量删除
      handleDelete: function (data) {
        var ids = '';
        for (var i = 0; i < data.params.length; i++) {
          ids = ids + data.params[i].id + ',';
        }
        data.t = 'shopReturn'
        data.ids = ids
        this.utils.request.deleteUserInfo(data, data.callback)

      },

      setStaus() {
        if (this.checked.length == 1) {
          this.dialogVisibleOpenTime = true;
          this.dataFormOpenTime.id = this.checked[0].id;
          this.dataFormOpenTime.serveno = this.checked[0].serveno;
          this.dataFormOpenTime.describe = this.checked[0].describe;
          this.dataFormOpenTime.status = this.checked[0].status;
        } else {
          this.$message({ message: "状态审核只能选择一条数据", type: "error" });
        }
      },
      // 菜单树选中
      deptTreeCurrentChangeHandle(data, node) {
        this.dataForm.deptId = data.id
        this.dataForm.deptName = data.name
      },

      selectionChange: function(params) {
        this.checked = params.selections;
      },
      // 编辑
      submitFormOpentime: function() {
        this.$refs.dataFormOpenTime.validate(valid => {
          if (valid) {
            this.$confirm("确认提交吗？", "提示", {}).then(() => {
              let params = Object.assign({}, this.dataFormOpenTime);

              params.t = "shopReturn";
              var this_ = this;
              this.utils.request.reviewStatus(params, function(res) {
                if (res.code == "0000") {
                  this_.$message({ message: "操作成功", type: "success" });

                  this_.$refs["dataFormOpenTime"].resetFields();

                  this_.dialogVisibleOpenTime = false;

                  this_.findPage(null);
                } else {
                  this_.$message({
                    message: "操作失败, " + res.msg,
                    type: "error"
                  });
                }
              });
            });
          }
        });
      },
      // 处理表格列过滤显示
      displayFilterColumnsDialog: function () {
        this.$refs.tableColumnFilterDialog.setDialogVisible(true)
      },
      // 处理表格列过滤显示
      handleFilterColumns: function (data) {
        this.filterColumns = data.filterColumns
        this.$refs.tableColumnFilterDialog.setDialogVisible(false)
      },
      // 处理表格列过滤显示
      initColumns: function () {
        this.columns = [
          {prop: "serveno", label: "服务编号", minWidth: 50},
          {prop: "number", label: "订单号", minWidth: 120},
          {prop: "username", label: "申请人", minWidth: 120},
          {prop: "NAME", label: "商品", minWidth: 120},
          {prop: "money", label: "申请退款金额", minWidth: 120},
          {prop: "paytypes", label: "付款方式", minWidth: 120},
          {prop: "reasontype", label: "退款原因", minWidth: 120},
          {prop: "saletype", label: "售后类型", minWidth: 120},
          {prop: "remark", label: "问题描述", minWidth: 120},
          {prop: "interventions", label: "平台介入", minWidth: 120},
          {prop: "statusval", label: "审核状态", minWidth: 120}

        ]
        var temp = [];
        $.each(this.columns, function (key, val) {
          temp.push(val)
        })
        this.filterColumns = temp;
      },
      //重置
      resetForm(formName) {
        this.$refs[formName].resetFields();
        this.findPage({'t': 'shopReturn'});

      },
      //性别式化
      sexFormatter(row, column, cellValue, index) {
        if (cellValue == 0) {
          return "男"
        } else if (cellValue == 1) {
          return "女"
        }
      },
    },
    mounted() {
      this.initColumns()

    }
  }

</script>

<style scoped>

</style>
